//
//  CourseClassInfoViewController.m
//  fitnessmanage
//
//  Created by wujian on 2017/10/22.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//  课程种类详情

#import "CourseClassInfoViewController.h"
#import "CourseClassInfoView.h"
#import "CourseClassInfoView.h"
//#import "EditClassCoverImageViewController.h"
//#import "EditClassInfoViewController.h"
//#import "EditClassInfoDetailViewController.h"
#import "HDAlertView.h"

@interface CourseClassInfoViewController ()

@end

@implementation CourseClassInfoViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

    self.title = @"课程种类详情";
    
    [self createSubView];
    
    //右侧图片 icon_nbarmore
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"icon_nbarmore"]
                                                                               imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightBtnClick)];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
}


-(void)createSubView{
    
    CourseClassInfoView *courseClassView = [[CourseClassInfoView alloc] initWithFrame:self.view.frame];
    
    courseClassView.userCommentArray = [[NSMutableArray alloc] init];
    
    courseClassView.courseDetailArray = [[NSMutableArray alloc] init];
    
    //编辑封面
    [courseClassView.editBtn addTarget:self action:@selector(editClassCoverBtnClick)];
    
    //编辑课程介绍
    [courseClassView.editCourseBtn addTarget:self action:@selector(editCourseBtn)];
    
    //上传课程图片和文字
    
    [self.view addSubview:courseClassView];
}

#pragma mark 编辑封面
-(void)editClassCoverBtnClick{
    
//    EditClassCoverImageViewController *editClassCoverImageVC = [[EditClassCoverImageViewController alloc] init];
//
//    editClassCoverImageVC.courseModel = self.courseModel;
//
//    [self.navigationController pushViewController:editClassCoverImageVC animated:YES];
}

#pragma mark 编辑课程介绍
-(void)editCourseBtn{
    
//    EditClassInfoViewController *editClassInfoVC = [[EditClassInfoViewController alloc] init];
//    
//    editClassInfoVC.courseModel = self.courseModel;
//    
//    [self.navigationController pushViewController:editClassInfoVC animated:YES];
}

#pragma mark 右侧按钮点击
-(void)rightBtnClick{
    
    __weak typeof(self)weakSelf = self;
    
    HDAlertView *alertView = [HDAlertView showActionSheetWithTitle:nil];
    
    alertView.buttonsListStyle = HDAlertViewButtonsListStyleRows;
    
    [alertView addButtonWithTitle:@"删除该课程种类" type:HDAlertViewButtonTypeCancel handler:^(HDAlertView *alertView) {
        
        [weakSelf deleCourse];
        
    }];
    
    [alertView addButtonWithTitle:@"取消" type:HDAlertViewButtonTypeDefault handler:^(HDAlertView *alertView) {
        
    }];
    
    [alertView show];
    
}


-(void)deleCourse{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示"message:@"确定删除该课程?"preferredStyle:UIAlertControllerStyleAlert];
    
    //添加取消到UIAlertController中
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    [alertController addAction:cancelAction];
    
    //添加确定到UIAlertController中
    UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        //Post_DelCourse
        
        [MBProgressHUD showMessage:@"删除中..." toView:self.view];
        
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        
//        [params setObject:self.courseModel.ID forKey:@"ID"];
        
        NSString *delUrl = [NSString stringWithFormat:@"%@/%@",Post_DelCourse,self.courseModel.ID];
        
        [HTTPTool POSTRaw:delUrl parameters:params success:^(id responseObject) {
            
            [MBProgressHUD hideHUDForView:self.view];
            
            if (responseObject && [[responseObject objectForKey:@"Code"] intValue] == 0){
                
                [MBProgressHUD showText:@"删除成功"];
                
                [NotificationCenter postNotificationName:@"ReloadCourse" object:nil];
                
                [self.navigationController popViewControllerAnimated:YES];
                
            }
            else{
                
                [MBProgressHUD showText:[responseObject objectForKey:@"Message"]];
            }
            
        } failure:^(NSError *error) {
            
            [MBProgressHUD hideHUDForView:self.view];
            [MBProgressHUD showText:@"删除失败"];
        }];
        
    }];
    
    [alertController addAction:OKAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
    
}
@end
